package com.sino.androiddesign.design

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.sino.androiddesign.R
import com.sino.androiddesign.common.ItemClickListener
import com.sino.androiddesign.recyclerviewdemo.BaseRecyclerAdapter
import com.sino.androiddesign.recyclerviewdemo.BaseRecyclerHolder
import com.sino.androiddesign.recyclerviewdemo.Bean
import kotlinx.android.synthetic.main.activity_design.*

/**
 * 材料设计控件
 * 参考: https://github.com/pinguo-zhouwei/MaterialDesignSamples
 */
class DesignActivity : AppCompatActivity(), ItemClickListener {

    override fun clickItemListener(position: Int) {
        when (position) {
            0 -> {
                startActivity(Intent(this, ToolbarActivity::class.java))
            }
            1->{
                startActivity(Intent(this,CATActivity::class.java))
            }

            2 ->{
                startActivity(Intent(this,TabActivity::class.java))
            }
            3 ->{

                startActivity(Intent(this,OtherActivity::class.java))
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_design)

        design_rv.layoutManager = LinearLayoutManager(this)
        var arrayList = ArrayList<Bean>()
        arrayList.add(Bean(text = "标题栏", img = R.mipmap.ic_launcher))
        arrayList.add(Bean(text = "可伸缩布局", img = R.mipmap.ic_launcher))
        arrayList.add(Bean(text = "标签", img = R.mipmap.ic_launcher))
        arrayList.add(Bean(text = "输入和提示", img = R.mipmap.ic_launcher))
        println("添加数据")
        var value = object : BaseRecyclerAdapter<Bean>(this, arrayList, R.layout.fragment_universal_adapter_item) {
            override fun convert(holder: BaseRecyclerHolder, item: Bean, position: Int) {
                holder.setImage(R.id.universal_item_iv, item.img)
                holder.setText(R.id.universal_item_tv, item.text)
            }
        }
        value.setClickListener(this)
        design_rv.adapter = value
        println("设置adapter")
    }
}
